import { Injectable, Logger } from "@nestjs/common";
import { CreateOrmDto } from "./dto/create-orm.dto";
import { UpdateOrmDto } from "./dto/update-orm.dto";
import { InjectRepository } from "@nestjs/typeorm";
import { Orm } from "./entities/orm.entity";
import { Repository } from "typeorm";
import { randomUUID } from "crypto";

@Injectable()
export class OrmService {
  private logger: Logger;

  constructor(@InjectRepository(Orm) private ormRepository: Repository<Orm>) {
    this.logger = new Logger("OrmServiceLogger");
  }

  create(createOrmDto: CreateOrmDto) {
    const data: Orm = new Orm();
    data.name = createOrmDto.name;
    data.uuid = randomUUID();
    this.logger.log(`add orm name: ${createOrmDto.name}`);
    this.ormRepository.save(data);
    return `add orm name: ${createOrmDto.name}`;
  }

  findAll() {
    return this.ormRepository.find();
  }

  findOne(id: number) {
    return `This action returns a #${id} orm`;
  }

  update(id: number, updateOrmDto: UpdateOrmDto) {
    return `This action updates a #${id} orm`;
  }

  remove(id: number) {
    return `This action removes a #${id} orm`;
  }
}
